package org.dromara.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.web.core.BaseController;
import org.dromara.system.domain.bo.IndexManagementBo;
import org.dromara.system.domain.vo.IndexManagementVo;
import org.dromara.system.service.IIndexManagementService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 指标管理
 *
 * @author Lion Li
 * @date 2025-10-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/management")
public class IndexManagementController extends BaseController {

    private final IIndexManagementService indexManagementService;

    /**
     * 查询指标管理列表
     */
    @SaCheckPermission("system:management:list")
    @GetMapping("/list")
    public R<List<IndexManagementVo>> list() {
        return R.ok(indexManagementService.queryList());
    }

    /**
     * 批量新增指标管理
     */
    @SaCheckPermission("system:management:add")
    @Log(title = "指标管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@RequestBody List<IndexManagementBo> indexManagementBoList) {
        return toAjax(indexManagementService.batchInsert(indexManagementBoList));
    }

    /**
     * 批量修改指标管理
     */
    @SaCheckPermission("system:management:edit")
    @Log(title = "指标管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@RequestBody List<IndexManagementBo> indexManagementBoList) {
        return toAjax(indexManagementService.batchUpdate(indexManagementBoList));
    }
}
